package com.ase.leetcode.数组中重复的数字;

import java.util.HashSet;
import java.util.Set;

/**
 * @author gyhstart
 * @create 2021/4/26 - 0:19
 **/
public class Solution2 {
    public static int findRepeatNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (set.contains(nums[i])){
                return nums[i];
            }
            set.add(nums[i]);
        }
        return -1;
    }

    public static void main(String[] args) {
        int repeatNumber = findRepeatNumber(new int[]{3, 3, 1, 0, 2, 5});
        System.out.println("repeatNumber = " + repeatNumber);
    }
}
